package chapter7.eg3;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.MessageToMessageEncoder;
import java.util.List;
import org.msgpack.MessagePack;

public class MessagePackEncoder extends MessageToByteEncoder<User> {

  @Override
  protected void encode(ChannelHandlerContext ctx, User user, ByteBuf out) throws Exception {
    MessagePack messagePack = new MessagePack();
    byte[] bytes = messagePack.write(user, new UserTemplate());
    out.writeBytes(bytes);
  }
}
